package com.miaoquan.mqapitbk.controller;

import com.miaoquan.mqapitbk.domain.request.TklCreateRequest;
import com.miaoquan.mqapitbk.service.TklService;
import com.miaoquan.mqcommon.api.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 淘口令Controller
 *
 * @author Fa
 * @date 2020-04-03 16:32
 */
@RestController
@RequestMapping("/tkl")
public class TklController {

    @Autowired
    private TklService tklService;

    /**
     * 生成淘口令
     */
    @PostMapping("/create")
    public CommonResult<String> createTkl(
//            @RequestParam(name = "userId", required = false) String userId,
//                                          @RequestParam(name = "text") String text,
//                                          @RequestParam(name = "url") String url,
//                                          @RequestParam(name = "logo", required = false) String logo
            @RequestBody TklCreateRequest tklCreateRequest
    ) {
//        String tkl = tklService.createTkl(userId, text, url, logo);
        String tkl = tklService.createTkl(
                tklCreateRequest.getUserId(),
                tklCreateRequest.getText(),
                tklCreateRequest.getUrl(),
                tklCreateRequest.getLogo());
        return CommonResult.success(tkl);
    }

}
